package com.example.util;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class SiKongMapDataUtil {

    public static boolean isDroneOsdData(Map<String, Object> map) {
        Object mapData = getMapData("data.host.night_lights_state", map);
        return mapData !=null;
    }


    public static boolean isHangarOsdData(Map<String, Object> map) {
        Object mapData = getMapData("data.host.drone_in_dock", map);
        return mapData !=null;
    }


    public static boolean isLiveCapacity(Map<String, Object> map) {
        Object mapData = getMapData("data.host.live_capacity", map);
        return mapData !=null;
    }

    public static boolean isLiveStatus(Map<String, Object> map) {
        Object mapData = getMapData("data.host.live_status", map);
        return mapData !=null;
    }

    /**
     * 这里只针对目前这个版本的司空数据，
     * */
    public static<T> T getMapData(String key,Map<String, Object> map) {
        try {
            String[] split = key.split("\\.");
            Map<String,Object>  temp = map;
            for (int i = 0; i < split.length; i++) {
                String s=split[i];
                Object o = temp.get(s);
                if (i ==split.length-1) {
                    return (T) o;
                }
                // 这里仅根当前mqtt 接受到的数据,目前用到的子属性为map 情况,其他情况暂不考虑
                if (!(o instanceof Map)) {
                    return null;
                }
                temp = (Map<String, Object>) o;
            }
        }catch (Exception e) {
            log.error("获取属性出错",e);
        }
        return null;
    }


}
